<?php
include '../../util/TransactionBD.php';
include '../../model/entidades/Pergunta.php';
 
class PerguntaGateway{
    
    public function inserirPergunta(Pergunta &$pergunta, $id_categoria){
        $sql = "INSERT INTO pergunta VALUES(NULL,'{$pergunta->getDescricao()}','{$pergunta->getAlternativaCorreta()}',$id_categoria);";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        $id = $con->lastInsertId();
        $pergunta->setId($id);
        TransactionBD::fechar();
    }


    public function alterarPergunta(Pergunta $pergunta){
        $sql = "UPDATE pergunta SET descricao = '{$pergunta->getDescricao()}', alternativa_correta = '{$pergunta->getAlternativaCorreta()}', id_categoria = '{$pergunta->getIdCategoria()}' WHERE pergunta.id = '{$pergunta->getId()}'";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        TransactionBD::fechar();
    }
    
    public function excluirPergunta($id){
        $sql = "DELETE FROM pergunta WHERE id='$id';";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        TransactionBD::fechar();
    }
}
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

